﻿using System;
using System.Linq;
using System.Text.Json.Serialization;

public class MediaInfoData
{
	public class InfoItem
	{
		[JsonPropertyName("@type")] public string ItemName = string.Empty;
		public int VideoCount;
		public int AudioCount;
		public int TextCount;
		public double Duration;
		public int Width;
		public int Height;

	}

	public class InfoItems
	{
		public InfoItem[]? track;
	}

	//****************************************************************************************

	public InfoItems? media;
#pragma warning disable CS0649
	[JsonIgnore] private InfoItem? _General;
	[JsonIgnore] private InfoItem? _Video;
#pragma warning restore CS0649
	[JsonIgnore] private InfoItem? General => _General ?? media?.track?.FirstOrDefault(p => p.ItemName.Equals("General", StringComparison.OrdinalIgnoreCase));
	[JsonIgnore] private InfoItem? Video => _Video ?? media?.track?.FirstOrDefault(p => p.ItemName.Equals("Video", StringComparison.OrdinalIgnoreCase));

	public int VideoCount => General?.VideoCount ?? 0;
	public int AudioCount => General?.AudioCount ?? 0;
	public int TextCount => General?.TextCount ?? 0;
	public double Duration => General?.Duration ?? 0;
	public int Width => Video?.Width ?? 0;
	public int Height => Video?.Height ?? 0;
	override public string ToString() => $"{{Duration:{Duration},Width:{Width},Height:{Height},VideoCount:{VideoCount},AudioCount:{AudioCount},TextCount:{TextCount}}}";
}